// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.nnee.p_fk.p_a;

import android.webkit.URLUtil;
import com.nnee.p_b.p_a.cls_d;
import com.nnee.p_c.cls_b;
import com.nnee.p_pr.p_a.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.Header;
import org.apache.http.HttpResponse;

// Referenced classes of package com.nnee.p_fk.a:
//            m, b, h

public class cls_k extends cls_m
{

    public cls_k(String s)
    {
        this(s, com.nnee.p_fk.p_a.cls_b.aGET);
    }

    public cls_k(String s, com.nnee.p_fk.p_a.cls_b b1)
    {
    	super(s, b1);
    	
        if(!URLUtil.isNetworkUrl(s))
            s = (new StringBuilder()).append("http://easyread.163.com").append(s).toString();
        
        b("User-Agent", (new StringBuilder()).append("Pris/").append(com.nnee.p_pr.p_a.cls_e.a(com.nnee.p_b.p_a.cls_d.h().a())).toString());
        b("X-User-Agent", c());
        b("Accept-Encoding", "gzip,deflate");
    }

    public cls_h a(HttpResponse httpresponse)
    {cls_h h1=null;
        String s;
        String s1;
        Header header;
        s = com.nnee.p_b.p_a.cls_d.h().c();
        s1 = com.nnee.p_b.p_a.cls_d.h().d();
        header = httpresponse.getFirstHeader("PRIS-WWW-Authenticate");
        if(header == null || header.getValue() == null) {
        	 if(httpresponse.getFirstHeader("WWW-Authenticate") != null)
                 h1 = new cls_h("Authorization", (new StringBuilder()).append("Basic ").append(cls_r.b((new StringBuilder()).append(s).append(":").append(s1).toString())).toString());
             else
                 h1 = super.a(httpresponse);
        	 
        }else 
        {
        	Matcher matcher = Pattern.compile("Digest\\s*realm=\"([^\"]+)\".*nonce=\"([^\"]+)\"").matcher(header.getValue());
            if(!matcher.find()) {
            	if(httpresponse.getFirstHeader("WWW-Authenticate") != null)
                    h1 = new cls_h("Authorization", (new StringBuilder()).append("Basic ").append(cls_r.b((new StringBuilder()).append(s).append(":").append(s1).toString())).toString());
                else
                    h1 = super.a(httpresponse);
            } else{
            	String s2;
                String s3;
                s2 = matcher.group(1);
                s3 = matcher.group(2);
                
                MessageDigest messagedigest=null;
				try {
					messagedigest = MessageDigest.getInstance("MD5");
				} catch (NoSuchAlgorithmException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                byte abyte0[] = messagedigest.digest((new StringBuilder()).append(s).append(":").append(s2).append(":").append(s3).toString().getBytes());
                byte abyte1[] = messagedigest.digest(s1.getBytes());
                byte abyte2[] = new byte[abyte0.length];
                for(int i = 0; i < abyte0.length; i++)
                    abyte2[i] = (byte)(abyte0[i] ^ abyte1[i]);

                String s4 = new String(cls_b.a(abyte2));
                h1 = new cls_h("PRIS-Authorization", (new StringBuilder()).append("Digest username=\"").append(s).append("\", realm=\"").append(s2).append("\", nonce=\"").append(s3).append("\", response=\"").append(s4).append("\"").toString());

            }
        }
        return h1;
 
    }

    String c()
    {
        android.content.Context context = com.nnee.p_b.p_a.cls_d.h().a();
        Object aobj[] = new Object[5];
        aobj[0] = com.nnee.p_pr.p_a.cls_e.b(context);
        aobj[1] = cls_u.m(context);
        aobj[2] = cls_q.b();
        aobj[3] = cls_u.r(context);
        aobj[4] = "1.0.1";
        return String.format("pris/%s (%s; android; %s; %s; android) %s", aobj);
    }

    public boolean d()
    {
        return true;
    }

    private static final String a = "Digest\\s*realm=\"([^\"]+)\".*nonce=\"([^\"]+)\"";
}
